package m202405.d14;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/14 14:15
 */
public class Q74 {

    public static void main(String[] args) {
        Q74 q74 = new Q74();
        q74.find(new int[]{-9,-7,-7,-5,-3},0,5,-4);
    }

    public boolean searchMatrix(int[][] matrix, int target) {
        for (int[] line : matrix) {
            if (target <= line[line.length - 1]) {
                return find(line, 0, line.length, target);
            }
        }
        return false;
    }

    private boolean find(int[] line, int start, int end, int target) {
        if (start + 1 == end) {
            return line[start] == target;
        }
        int mid = (start + end) / 2;
        if (target < line[mid]) {
            return find(line, start, mid, target);
        } else if (target > mid) {
            return find(line, mid, end, target);
        } else {
            return true;
        }
    }
}
